home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / bin / DXUtils / AppWizard / DXAppwiz.awx / TEMPLATE / GDI_WIN.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  11.3 KB  |  312 lines

  1. //-----------------------------------------------------------------------------
  2. // File: $$root$$.h
  3. //
  4. // Desc: Header file $$root$$ sample app
  5. //-----------------------------------------------------------------------------
  6. #ifndef $$FILE_NAME_SYMBOL$$_INCLUDED_
  7. #define $$FILE_NAME_SYMBOL$$_INCLUDED_
  8. $$IF(DPLAY)
  9.  
  10.  
  11.  
  12.  
  13. //-----------------------------------------------------------------------------
  14. // Player context locking defines
  15. //-----------------------------------------------------------------------------
  16. CRITICAL_SECTION g_csPlayerContext;
  17. #define PLAYER_LOCK()                   EnterCriticalSection( &g_csPlayerContext ); 
  18. #define PLAYER_ADDREF( pPlayerInfo )    if( pPlayerInfo ) pPlayerInfo->lRefCount++;
  19. #define PLAYER_RELEASE( pPlayerInfo )   if( pPlayerInfo ) { pPlayerInfo->lRefCount--; if( pPlayerInfo->lRefCount <= 0 ) SAFE_DELETE( pPlayerInfo ); } pPlayerInfo = NULL;
  20. #define PLAYER_UNLOCK()                 LeaveCriticalSection( &g_csPlayerContext );
  21.  
  22. CRITICAL_SECTION g_csWorldStateContext;
  23. #define WORLD_LOCK()                   EnterCriticalSection( &g_csWorldStateContext ); 
  24. #define WORLD_UNLOCK()                 LeaveCriticalSection( &g_csWorldStateContext );
  25. $$ENDIF
  26.  
  27.  
  28.  
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Defines, and constants
  32. //-----------------------------------------------------------------------------
  33. // TODO: change "DirectX AppWizard Apps" to your name or the company name
  34. #define DXAPP_KEY        TEXT("Software\\DirectX AppWizard Apps\\$$root$$")
  35.  
  36.  
  37.  
  38. $$IF(DPLAY)
  39. // Associate a structure with every network player
  40. struct APP_PLAYER_INFO
  41. {
  42.     // TODO: change as needed
  43.     LONG  lRefCount;                        // Ref count so we can cleanup when all threads 
  44.                                             // are done w/ this object
  45.     DPNID dpnidPlayer;                      // DPNID of player
  46.     TCHAR strPlayerName[MAX_PATH];          // Player name
  47.  
  48. $$IF(ACTIONMAPPER)
  49.     FLOAT fAxisRotateUD;                    // State of axis for this player
  50.     FLOAT fAxisRotateLR;                    // State of axis for this player
  51. $$ELSE
  52.     BOOL  bRotateUp;                       // State of up button or this player
  53.     BOOL  bRotateDown;                     // State of down button or this player
  54.     BOOL  bRotateLeft;                     // State of left button or this player
  55.     BOOL  bRotateRight;                    // State of right button or this player
  56. $$ENDIF
  57. $$IF(DPLAYVOICE)
  58.  
  59.     BOOL  bHalfDuplex;                      // TRUE if player is in half-duplex mode
  60.     BOOL  bTalking;                         // TRUE if player is talking
  61. $$ENDIF
  62.  
  63.     APP_PLAYER_INFO* pNext;
  64.     APP_PLAYER_INFO* pPrev;
  65. };
  66.  
  67.  
  68. $$ENDIF // end DPLAY
  69. $$IF(ACTIONMAPPER)
  70. // DirectInput action mapper reports events only when buttons/axis change
  71. // so we need to remember the present state of relevant axis/buttons for 
  72. // each DirectInput device.  The CInputDeviceManager will store a 
  73. // pointer for each device that points to this struct
  74. struct InputDeviceState
  75. {
  76.     // TODO: change as needed
  77.     FLOAT fAxisRotateLR;
  78.     BOOL  bButtonRotateLeft;
  79.     BOOL  bButtonRotateRight;
  80.  
  81.     FLOAT fAxisRotateUD;
  82.     BOOL  bButtonRotateUp;
  83.     BOOL  bButtonRotateDown;
  84. $$IF(DMUSIC || DSOUND)
  85.  
  86.     BOOL  bButtonPlaySoundButtonDown;
  87. $$ENDIF
  88. };
  89.  
  90.  
  91. $$ENDIF
  92. // Struct to store the current input state
  93. struct UserInput
  94. {
  95. $$IF(KEYBOARD)
  96.     BYTE diks[256];   // DirectInput keyboard state buffer 
  97.  
  98. $$ENDIF
  99.     // TODO: change as needed
  100. $$IF(ACTIONMAPPER)
  101.     FLOAT fAxisRotateUD;
  102.     FLOAT fAxisRotateLR;
  103. $$ELSE // start !ACTIONMAPPER --> (KEYBOARD || !DINPUT)
  104.     BOOL bRotateUp;
  105.     BOOL bRotateDown;
  106.     BOOL bRotateLeft;
  107.     BOOL bRotateRight;
  108. $$ENDIF 
  109. $$IF(DMUSIC || DSOUND)
  110.     BOOL bPlaySoundButtonDown;
  111. $$ENDIF
  112. $$IF(ACTIONMAPPER)
  113.     BOOL bDoConfigureInput;
  114. $$ENDIF
  115. $$IF(DPLAYVOICE)
  116.     BOOL bDoConfigureVoice;
  117. $$ENDIF
  118. };
  119.  
  120.  
  121. $$IF(DPLAY)
  122. //-----------------------------------------------------------------------------
  123. // App specific DirectPlay messages and structures 
  124. //-----------------------------------------------------------------------------
  125.  
  126. // TODO: change or add app specific DirectPlay messages and structures as needed
  127. #define GAME_MSGID_WORLDSTATE    1
  128. #define GAME_MSGID_INPUTSTATE    2
  129. #define GAME_MSGID_HOSTPAUSE     3
  130.  
  131. // Change compiler pack alignment to be BYTE aligned, and pop the current value
  132. #pragma pack( push, 1 )
  133.  
  134. struct GAMEMSG_GENERIC
  135. {
  136.     // One of GAME_MSGID_* IDs so the app knows which GAMEMSG_* struct
  137.     // to cast the msg pointer into.
  138.     WORD nType; 
  139. };
  140.  
  141. struct GAMEMSG_WORLDSTATE : public GAMEMSG_GENERIC
  142. {
  143.     FLOAT fWorldRotX;
  144.     FLOAT fWorldRotY;
  145. };
  146.  
  147. struct GAMEMSG_INPUTSTATE : public GAMEMSG_GENERIC
  148. {
  149. $$IF(ACTIONMAPPER)
  150.     FLOAT fAxisRotateUD;
  151.     FLOAT fAxisRotateLR;
  152. $$ELSE
  153.     BOOL  bRotateUp;   
  154.     BOOL  bRotateDown; 
  155.     BOOL  bRotateLeft; 
  156.     BOOL  bRotateRight;
  157. $$ENDIF
  158. };
  159.  
  160. struct GAMEMSG_HOSTPAUSE : public GAMEMSG_GENERIC
  161. {
  162.     BOOL bHostPause;
  163. };
  164.  
  165. // Pop the old pack alignment
  166. #pragma pack( pop )
  167.  
  168.  
  169. $$ENDIF
  170.  
  171.  
  172.  
  173. //-----------------------------------------------------------------------------
  174. // Name: class CMyApplication 
  175. // Desc: Application class.
  176. //-----------------------------------------------------------------------------
  177. class CMyApplication 
  178. {
  179.     BOOL                    m_bLoadingApp;          // TRUE, if the app is loading
  180.     BOOL                      m_bHasFocus;        // TRUE, if the app has focus
  181.     TCHAR*                  m_strWindowTitle;       // Title for the app's window
  182.     HWND                    m_hWnd;                 // The main app window
  183.     FLOAT                   m_fTime;                // Current time in seconds
  184.     FLOAT                   m_fElapsedTime;         // Time elapsed since last frame
  185.  
  186.     DWORD                   m_dwCreationWidth;      // Width used to create window
  187.     DWORD                   m_dwCreationHeight;     // Height used to create window
  188.  
  189. $$IF(KEYBOARD)
  190.     LPDIRECTINPUT8          m_pDI;                  // DirectInput object
  191.     LPDIRECTINPUTDEVICE8    m_pKeyboard;            // DirectInput keyboard device
  192. $$ENDIF
  193. $$IF(ACTIONMAPPER)
  194.     CInputDeviceManager*    m_pInputDeviceManager;  // DirectInput device manager
  195.     DIACTIONFORMAT          m_diafGame;             // Action format for game play
  196. $$ENDIF
  197.     UserInput               m_UserInput;            // Struct for storing user input 
  198.  
  199. $$IF(DMUSIC || DSOUND)
  200.     FLOAT                   m_fSoundPlayRepeatCountdown; // Sound repeat timer
  201. $$IF(DMUSIC)
  202.     CMusicManager*          m_pMusicManager;        // DirectMusic manager class
  203.     CMusicSegment*          m_pBounceSound;         // Bounce sound
  204. $$ELSE // start !DMUSIC
  205.     CSoundManager*          m_pSoundManager;        // DirectSound manager class
  206.     CSound*                 m_pBounceSound;         // Bounce sound
  207. $$ENDIF // end DMUSIC
  208.  
  209. $$ENDIF // end (DMUSIC || DSOUND)
  210. $$IF(DPLAY)
  211.     IDirectPlay8Peer*       m_pDP;                  // DirectPlay peer object
  212.     CNetConnectWizard*      m_pNetConnectWizard;    // Connection wizard
  213.     IDirectPlay8LobbiedApplication* m_pLobbiedApp;  // DirectPlay lobbied app 
  214.     BOOL                    m_bWasLobbyLaunched;    // TRUE if lobby launched
  215.     DPNID                   m_dpnidLocalPlayer;     // DPNID of local player
  216.     LONG                    m_lNumberOfActivePlayers;        // Number of players currently in game
  217.     TCHAR                   m_strLocalPlayerName[MAX_PATH];  // Local player name
  218.     TCHAR                   m_strSessionName[MAX_PATH];      // Session name
  219.     TCHAR                   m_strPreferredProvider[MAX_PATH];// Provider string
  220.     APP_PLAYER_INFO         m_PlayInfoList;         // List of players
  221.     APP_PLAYER_INFO*        m_pLocalPlayerInfo;     // APP_PLAYER_INFO struct for local player
  222.     HRESULT                 m_hrNet;                // HRESULT of DirectPlay events
  223.     FLOAT                   m_fWorldSyncTimer;      // Timer for syncing world state between players
  224.     BOOL                    m_bHostPausing;         // Has the host paused the app?
  225.     UserInput               m_CombinedNetworkInput; // Combined input from all network players
  226.  
  227. $$ENDIF
  228. $$IF(DPLAYVOICE)
  229.     CNetVoice*              m_pNetVoice;            // DirectPlay voice helper class
  230.     DVCLIENTCONFIG          m_dvClientConfig;       // Voice client config
  231.     GUID                    m_guidDVSessionCT;      // GUID for choosen voice compression
  232.     BOOL                    m_bNetworkPlayersTalking; // TRUE if any of the network players are talking
  233.     BOOL                    m_bLocalPlayerTalking;  // TRUE if the local player is talking
  234.  
  235. $$ENDIF
  236.     FLOAT                   m_fWorldRotX;           // World rotation state X-axis
  237.     FLOAT                   m_fWorldRotY;           // World rotation state Y-axis
  238.  
  239. protected:
  240.     HRESULT OneTimeSceneInit();
  241.     HRESULT Render();
  242.     HRESULT FrameMove();
  243.     HRESULT FinalCleanup();
  244.  
  245.     HRESULT RenderText();
  246.  
  247. $$IF(DINPUT)
  248.     HRESULT InitInput( HWND hWnd );
  249. $$ENDIF // end DINPUT
  250.     void    UpdateInput( UserInput* pUserInput );
  251. $$IF(DPLAY)
  252.     HRESULT CombineInputFromAllPlayers( UserInput* pCombinedUserInput );
  253. $$ENDIF // end DPLAY
  254. $$IF(DINPUT)
  255.     void    CleanupDirectInput();
  256. $$ENDIF // end DINPUT
  257.  
  258. $$IF(DMUSIC || DSOUND)
  259.     HRESULT InitAudio( HWND hWnd );
  260.  
  261. $$ENDIF
  262. $$IF(DPLAY)
  263.     HRESULT InitDirectPlay();
  264.     void    CleanupDirectPlay();
  265.     HRESULT ConnectViaDirectPlay();
  266.     HRESULT SendLocalInputIfChanged();
  267.     HRESULT SendWorldStateToAll();
  268.     HRESULT SendPauseMessageToAll( BOOL bPause );
  269.  
  270. $$ENDIF
  271. $$IF(DPLAYVOICE)
  272.     HRESULT InitDirectPlayVoice();
  273.     VOID    UpdateTalkingVariables();
  274.     HRESULT UserConfigVoice();
  275.  
  276. $$ENDIF
  277.     VOID    ReadSettings();
  278.     VOID    WriteSettings();
  279.  
  280. public:
  281.     HRESULT Create( HINSTANCE hInstance );
  282.     INT     Run();
  283.     LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  284.     VOID    Pause( BOOL bPause );
  285.  
  286.     CMyApplication();
  287. $$IF(ACTIONMAPPER)
  288.  
  289.     HRESULT InputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi );
  290.     static HRESULT CALLBACK StaticInputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi, LPVOID pParam );   
  291. $$ENDIF
  292. $$IF(DPLAY)
  293.  
  294.     static HRESULT WINAPI StaticDirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  295.     HRESULT DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  296.     static HRESULT WINAPI StaticDirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  297.     HRESULT DirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  298. $$ENDIF
  299. $$IF(DPLAYVOICE)
  300.  
  301.     static HRESULT WINAPI StaticDirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  302.     HRESULT DirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  303.     static HRESULT WINAPI StaticDirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  304.     HRESULT DirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  305. $$ENDIF
  306. };
  307.  
  308.  
  309.  
  310.  
  311. #endif // !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)
  312.